﻿using Global;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
using Microsoft.OpenApi.Writers;
using ProdService;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Text;
using static Global.Const;
using ViewModels.JsonResult;

namespace UI.ApiControllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class PhoneController : BaseController
    {
        public PhoneController(PhoneService phoneService, UserService userService)
            : base(userService, phoneService)
        {
        }

        [HttpGet(nameof(Exist))]
        public bool Exist(string number)
        {
            bool exist = phoneService.GetBy(number)?.User == null;
            return exist;

        }

        [HttpGet]
        [Route(nameof(Send))]
        public WithError Send(string captcha, string number)
        {
            WithError result = checkCaptcha(captcha); ;

            if (result.Errors.Count > 0)
            {
                return result;
            }

            phoneService.Send(number);

            result.Succeed = result.Errors.Count() == 0;
            return result;
        }


    }
}
